package com.handong.handserialprogram.model.entities;

import android.nfc.Tag;
import android.os.Parcel;
import android.os.Parcelable;
import android.util.Log;

import com.handong.handserialprogram.model.status.FootRingStatus;

import java.io.Serializable;
import java.util.Date;

import static com.loopj.android.http.AsyncHttpClient.log;

/**
 * Created by Administrator on 2016/12/21.
 */
public class FootRingNewEntity implements Parcelable,Serializable {
    /**
     * 实体数据
     */
    private float actualRingDistance = 0.0F;//实测距离
    private int lockType = 0;//锁的状态,0锁关,1锁开,2授权打开,-1未知
    private String ringID;//脚环ID
    private int ringPower=-1;//电量，-1未知
    private int setRingDistance = 8;//设置的距离
    //private byte simStatus;
    private String IMEI_CCR="";
    private String ip;
    private String port;
    private String sim;
    private String version;
    private String criminalName="";

    public int getPowerlowCount() {
        return powerlowCount;
    }

    public void setPowerlowCount(int powerlowCount) {
        this.powerlowCount = powerlowCount;
    }

    private int powerlowCount=0;

    public boolean isResponseDistance() {
        return isResponseDistance;
    }

    public void setResponseDistance(boolean responseDistance) {
        isResponseDistance = responseDistance;
    }

    private boolean isResponseDistance=false;

    public Boolean getEscapeFirst() {
        return isEscapeFirst;
    }

    public void setEscapeFirst(Boolean escape) {
        isEscapeFirst = escape;
    }

    private Boolean isEscapeFirst=false;

    public int getDataCount() {
        return DataCount;
    }

    public void setDataCount(int dataCount) {
        DataCount = dataCount;
    }

    private int DataCount=0;//为了特殊处理，前三包会有测距失败的情况，不计入信号弱计算

    public boolean isStopMissionReceive() {
        return isStopMissionReceive;
    }

    public void setStopMissionReceive(boolean stopMissionReceive) {
        isStopMissionReceive = stopMissionReceive;
    }

    private boolean isStopMissionReceive=false;

    public boolean isReceiveData() {
        return isReceiveData;
    }

    public void setReceiveData(boolean receiveData) {
        isReceiveData = receiveData;
    }

    private boolean isReceiveData=false;

    public int getStopMissionNoDataCount() {
        return stopMissionNoDataCount;
    }

    public void setStopMissionNoDataCount(int stopMissionNoDataCount) {
        this.stopMissionNoDataCount = stopMissionNoDataCount;
    }

    private int stopMissionNoDataCount=0;

    public byte getCurrentIndex() {
        return currentIndex;
    }

    public void setCurrentIndex(byte currentIndex) {
        this.currentIndex = currentIndex;
    }

    private byte currentIndex=10;

    public boolean isOverSetDistance() {
        return isOverSetDistance;
    }

    public void setOverSetDistance(boolean overSetDistance) {
        isOverSetDistance = overSetDistance;
    }

    private boolean isOverSetDistance=false;

    public int getReceiveCount() {
        return receiveCount;
    }

    public void setReceiveCount(int receiveCount) {
        this.receiveCount = receiveCount;
    }

    private int receiveCount=0;

    public float getTotalRingDistance() {
        return totalRingDistance;
    }

    public void setTotalRingDistance(float totalRingDistance) {
        this.totalRingDistance = totalRingDistance;
    }

    private float totalRingDistance=0.0F;//距离和



    public String getCriminalName() {
        return criminalName;
    }

    public void setCriminalName(String criminalName) {
        this.criminalName = criminalName;
    }

    public String getCriminalId() {
        return criminalId;
    }

    public void setCriminalId(String criminalId) {
        this.criminalId = criminalId;
    }

    private String criminalId="";
    private int voiceNumber;

    /**
     * 定义数据-------------
     */
    private int brokenType = -1;//防拆 0正常，1已被破坏，-1未知
    private boolean isAction = false;
    private boolean isNormalWork = false;//正常工作
    private boolean myBingding=false;//是否是自己绑定的
    private boolean isBingding=false;//是否被绑定

    public boolean isEmpower() {
        return isEmpower;
    }

    public void setEmpower(boolean empower) {
        isEmpower = empower;
    }
    private boolean isWithdraw=false;//是否打开临时撤防

    public boolean isWithdraw() {
        return isWithdraw;
    }

    public void setWithdraw(boolean withdraw) {
        isWithdraw = withdraw;
    }

    private boolean isEmpower=false;//是否授权打开
    private boolean isRefresh = false;
    public static final int LOCK_OPEN = 1;//锁开
    public static final int LOCK_CLOSE = 0;//锁关
    public static final int LOCK_EMPOWER_OPEN=2;//授权打开
    public static final short LONG_WAIT = 13;
    public static final int STATE_NORMAL_LIMIT = 2;//3s无数据情况为355ms左右加1
    public static final int STATE_ESCAPE_LIMIT = 4;//5s
    public static final int STATE_ESCAPE_LIMIT_NO_OVERDISTANCE = 10;//15s直接逃脱没有差距，15秒逃脱

    public long getCreateTime() {
        return CreateTime;
    }

    public void setCreateTime(long createTime) {
        CreateTime = createTime;
    }

    private long CreateTime;
    private short actionCount = 0;//活动数
    private int noDataTime = 0;//时间
    private byte actionOrder = 0;
    private boolean isLockAlarm=false;
    private boolean isBreakAlarm=false;
    private boolean isHandAlarm=false;
    private boolean isStopAlarm=false;
    private boolean isOverHangAlarm=false;
    private boolean isEscapeAlarm=false;
    private boolean isShakeAlarm=false;
    private boolean isLoginOutAlarm=false;

    private boolean ringUpdate=false;

    public boolean isRingUpdate() {
        return ringUpdate;
    }

    public void setRingUpdate(boolean ringUpdate) {
        this.ringUpdate = ringUpdate;
    }

    public byte getTaskTime() {
        return taskTime;
    }

    public void setTaskTime(byte taskTime) {
        this.taskTime = taskTime;
    }

    public byte getUwbCycle() {
        return uwbCycle;
    }

    public void setUwbCycle(byte uwbCycle) {
        this.uwbCycle = uwbCycle;
    }

//    private byte task=8;

    public boolean isPhoneSend() {
        return isPhoneSend;
    }

    public void setPhoneSend(boolean phoneSend) {
        isPhoneSend = phoneSend;
    }

    public boolean isPhoneSend=true;

    public boolean isWork() {
        return isWork;
    }

    public void setWork(boolean work) {
        isWork = work;
    }
    //false为测试状态，true为正常运行状态
    public boolean isWork=false;
    private byte taskTime=0;
    private byte uwbCycle=0;
    private int isActive=32;
    private int truePower=0;

    public int getTruePower() {
        return truePower;
    }

    public void setTruePower(int truePower) {
        this.truePower = truePower;
    }

    private boolean isAudioError=false;

    public boolean isDelete() {
        return isDelete;
    }

    public void setDelete(boolean delete) {
        isDelete = delete;
    }

    private boolean isDelete=false;

    public boolean isOverHangAlarm() {
        return isOverHangAlarm;
    }

    public void setOverHangAlarm(boolean overHangAlarm) {
        isOverHangAlarm = overHangAlarm;
    }

    public boolean isEscapeAlarm() {
        return isEscapeAlarm;
    }

    public void setEscapeAlarm(boolean escapeAlarm) {
        isEscapeAlarm = escapeAlarm;
    }

    public boolean isShakeAlarm() {
        return isShakeAlarm;
    }

    public void setShakeAlarm(boolean shakeAlarm) {
        isShakeAlarm = shakeAlarm;
    }

    public boolean isLoginOutAlarm() {
        return isLoginOutAlarm;
    }

    public void setLoginOutAlarm(boolean loginOutAlarm) {
        isLoginOutAlarm = loginOutAlarm;
    }

    private byte taskResp=0;

    public byte getTaskResp() {
        return taskResp;
    }

    public void setTaskResp(byte taskResp) {
        this.taskResp = taskResp;
    }

    public int getIsActive() {
        return isActive;
    }

    public void setIsActive(int isActive) {
        this.isActive = isActive;
    }

    private int isSync=0;

    public int getIsSync() {
        return isSync;
    }

    public void setIsSync(int isSync) {
        this.isSync = isSync;
    }

    public int getIsCheck() {
        return isCheck;
    }

    public void setIsCheck(int isCheck) {
        this.isCheck = isCheck;
    }

    private int isCheck=0;

    public boolean isLockAlarm() {
        return isLockAlarm;
    }

    public void setLockAlarm(boolean lockAlarm) {
        isLockAlarm = lockAlarm;
    }

    public boolean isAudioError() {
        return isAudioError;
    }

    public void setAudioError(boolean audioError) {
        isAudioError = audioError;
    }

    public boolean isBreakAlarm() {
        return isBreakAlarm;

    }

    public void setBreakAlarm(boolean breakAlarm) {
        isBreakAlarm = breakAlarm;
    }

    public boolean isHandAlarm() {
        return isHandAlarm;
    }

    public void setHandAlarm(boolean handAlarm) {
        isHandAlarm = handAlarm;
    }

    public boolean isStopAlarm() {
        return isStopAlarm;
    }

    public void setStopAlarm(boolean stopAlarm) {
        isStopAlarm = stopAlarm;
    }

    public boolean isSouding() {
        return isSouding;
    }

    public void setSouding(boolean souding) {
        isSouding = souding;
    }

    public boolean isLoginOut() {
        return isLoginOut;
    }

    public void setLoginOut(boolean loginOut) {
        isLoginOut = loginOut;
    }

    public boolean isResult() {
        return isResult;
    }

    public void setResult(boolean result) {
        isResult = result;
    }

    public boolean isUwbError() {
        return isUwbError;
    }

    public void setUwbError(boolean uwbError) {
        isUwbError = uwbError;
    }

    public boolean isIs4gError() {
        return is4gError;
    }

    public void setIs4gError(boolean is4gError) {
        this.is4gError = is4gError;
    }

    public boolean isWifiError() {
        return isWifiError;
    }

    public void setWifiError(boolean wifiError) {
        isWifiError = wifiError;
    }

    private boolean isSouding=false;
    private boolean isLoginOut=false;
    private boolean isResult=false;
    private boolean isUwbError=false;
    private boolean is4gError=false;
    private boolean isWifiError=false;
    private boolean isSimError=false;

    public boolean isOverHang() {
        return isOverHang;
    }

    public void setOverHang(boolean overHang) {
        isOverHang = overHang;
    }

    public boolean isEscape() {
        return isEscape;
    }

    public void setEscape(boolean escape) {
        isEscape = escape;
    }

    public boolean isShake() {
        return isShake;
    }

    public void setShake(boolean shake) {
        isShake = shake;
    }

    public boolean isPowerLow() {
        return isPowerLow;
    }

    public void setPowerLow(boolean powerLow) {
        isPowerLow = powerLow;
    }

    public boolean isPowerDown() {
        return isPowerDown;
    }

    public void setPowerDown(boolean powerDown) {
        isPowerDown = powerDown;
    }

    private boolean isOverHang=false;

    public boolean isOverLeval() {
        return isOverLeval;
    }

    public void setOverLeval(boolean overLeval) {
        isOverLeval = overLeval;
    }

    private boolean isOverLeval=false;
    private boolean isEscape=false;
    private boolean isShake=false;
    private boolean isPowerLow=false;
    private boolean isPowerDown=false;

    public byte getCheckStatus() {
        return checkStatus;
    }

    public void setCheckStatus(byte checkStatus) {
        this.checkStatus = checkStatus;
    }

    private byte checkStatus;

    public boolean isSimError() {
        return isSimError;
    }

    public void setSimError(boolean simError) {
        isSimError = simError;
    }

    public FootRingNewEntity() {
    }

    protected FootRingNewEntity(Parcel in) {
        ringID = in.readString();
        setRingDistance = in.readInt();
        actualRingDistance = in.readFloat();
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeString(ringID);
        dest.writeInt(setRingDistance);
        dest.writeFloat(actualRingDistance);
    }

    @Override
    public int describeContents() {
        return 0;
    }

    public static final Creator<FootRingNewEntity> CREATOR = new Creator<FootRingNewEntity>() {
        @Override
        public FootRingNewEntity createFromParcel(Parcel in) {
            return new FootRingNewEntity(in);
        }

        @Override
        public FootRingNewEntity[] newArray(int size) {
            return new FootRingNewEntity[size];
        }
    };

    public void addActionCount() {
        if (this.actionCount <= LONG_WAIT) {
            this.actionCount++;
        }
    }

    public void calculateTime() {
        //Log.d("nodata","当前次数"+this.noDataTime);
        if (this.isOverSetDistance()&&this.noDataTime <= STATE_ESCAPE_LIMIT) {
            this.noDataTime += 1;
            Log.d("noDataTime", "calculateTime: "+this.noDataTime );
            return;
        }
        if (!this.isOverSetDistance()&&this.noDataTime <= STATE_ESCAPE_LIMIT_NO_OVERDISTANCE)
        {
            this.noDataTime += 1;
            Log.d("noDataTime", "calculateTime: "+this.noDataTime );
            return;
        }
        Log.d("noDataTime", "calculateTime: "+this.noDataTime );
        this.actualRingDistance = 0.0f;
        this.totalRingDistance=0.0f;

    }

    /**
     * 判断上一包是不是正常收到
     * @return
     */
    public boolean isSendLoginOut()
    {
        return this.noDataTime<=1;
    }
    /**
     * 判断脚环状态-超时处理
     * @return
     */
    public int getStatus() {
        Log.d("noDataTime", "getStatus: "+this.noDataTime );
        if (!this.isResponseDistance()&& this.noDataTime <=STATE_ESCAPE_LIMIT)
        {
            return FootRingStatus.NODATA;
        }
        if (this.isResponseDistance()&&this.noDataTime <= STATE_NORMAL_LIMIT) {//7秒
            return FootRingStatus.NORMAL;
        }
        if ((this.isResponseDistance()&&this.isOverSetDistance()&&this.noDataTime > STATE_NORMAL_LIMIT && this.noDataTime <=STATE_ESCAPE_LIMIT)||(this.isResponseDistance()&&!this.isOverSetDistance()&&this.noDataTime > STATE_NORMAL_LIMIT && this.noDataTime <=STATE_ESCAPE_LIMIT_NO_OVERDISTANCE)){//7-10秒
            //Log.d("异常", "getStatus: "+this.noDataTime );
            return FootRingStatus.EXCEPTION;
        }
        this.actualRingDistance=0.0f;
        return FootRingStatus.ESCAPE;//大于等于30就是逃脱
    }

    /**
     * 判断是不是信号弱
     * @return
     */
    public boolean isSignlarWeek(){
        return this.noDataTime > STATE_NORMAL_LIMIT;
    }

    public short getActionCount() {
        return this.actionCount;
    }

    public byte getActionOrder() {
        return this.actionOrder;
    }

    public float getActualRingDistance() {
        return this.actualRingDistance;
    }

    public int getBrokenType() {
        return this.brokenType;
    }

    public int getLockType() {
        return this.lockType;
    }

    public int getNoDataTime() {
        return this.noDataTime;
    }

    public String getRingID() {
        return this.ringID;
    }

    public int getRingPower() {
        return this.ringPower;
    }

    public int getSetRingDistance() {
        return this.setRingDistance;
    }



    public boolean isAction() {
        return this.isAction;
    }

    public boolean isNormalWork() {
        return this.isNormalWork;
    }

    public boolean isRefresh() {
        return this.isRefresh;
    }

    public void resetActionCount() {
        this.actionCount = 0;
    }

    public void resetActionOrder() {
        this.actionOrder = 0;
    }

    public void resetTime() {
        this.noDataTime = 0;
    }

    public void setAction(boolean paramBoolean) {
        this.isAction = paramBoolean;
    }

    public void setActionOrder(byte paramByte) {
        this.actionOrder = paramByte;
    }

    public void setActualRingDistance(float paramFloat) {
        this.actualRingDistance = paramFloat;
    }

    public void setBrokenType(int paramString) {
        this.brokenType = paramString;
    }

    public void setLockType(int paramInt) {
        this.lockType = paramInt;
    }

    public void setNormalWork(boolean paramBoolean) {
        this.isNormalWork = paramBoolean;
    }

    public void setRefresh(boolean paramBoolean) {
        this.isRefresh = paramBoolean;
    }

    public void setRingID(String paramString) {
        this.ringID = paramString;
    }

    public void setRingPower(int paramString) {
        this.ringPower = paramString;
    }

    public void setSetRingDistance(int paramInt) {
        this.setRingDistance = paramInt;
    }

//    public byte getSimStatus() {
//        return simStatus;
//    }
//
//    public void setSimStatus(byte simStatus) {
//        this.simStatus = simStatus;
//    }

    public String getIMEI_CCR() {
        return IMEI_CCR;
    }

    public void setIMEI_CCR(String IMEI_CCR) {
        this.IMEI_CCR = IMEI_CCR;
    }

    public boolean isMyBingding() {
        return myBingding;
    }

    public void setMyBingding(boolean myBingding) {
        this.myBingding = myBingding;
    }

    public boolean isBingding() {
        return isBingding;
    }

    public void setBingding(boolean bingding) {
        isBingding = bingding;
    }


    public String getIp() {
        return ip;
    }

    public void setIp(String ip) {
        this.ip = ip;
    }

    public String getPort() {
        return port;
    }

    public void setPort(String port) {
        this.port = port;
    }

    public String getSim() {
        return sim;
    }

    public void setSim(String sim) {
        this.sim = sim;
    }

    public String getVersion() {
        return version;
    }

    public void setVersion(String version) {
        this.version = version;
    }

    public int getVoiceNumber() {
        return voiceNumber;
    }

    public void setVoiceNumber(int voiceNumber) {
        this.voiceNumber = voiceNumber;
    }

    @Override
    public boolean equals(Object object) {
        if(object==null)return false;
        if(object instanceof FootRingNewEntity){
            FootRingNewEntity entity = (FootRingNewEntity) object;
            return this.ringID.equals(entity.getRingID());
        }
     return false;
    }

    public String toString() {
        return "FootRing:" + this.ringID + ", normalWork:" + this.isNormalWork + ", actionCount:" + this.actionCount;
    }

    public void setNoDataTime(int noDataTime) {
        this.noDataTime = noDataTime;
    }


    public boolean isInteraction() {
        return isInteraction;
    }

    public void setInteraction(boolean interaction) {
        isInteraction = interaction;
    }

    private boolean isInteraction=true;
}
